//
//  tempView.m
//  sdk2.0zhengquandasha
//
//  Created by Choi on 15/12/18.
//  Copyright © 2015年 palmaplus. All rights reserved.
//

#import "locationStyleView.h"
@interface locationStyleView ()
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIImageView *oldImageView;
//@property (nonatomic,assign)LocationStyle locStyle;
@end


@implementation locationStyleView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
//        self.layer.cornerRadius = 20;
//        self.layer.borderWidth = 1.0;
        self.backgroundColor = [UIColor whiteColor];
        [self setTitleArray:nil];
    }
    return self;
}

-(void)setTitleArray:(NSArray *)titleArray{
    //添加定位模式视图
    UILabel *label = [self addTitleView:@"请选择定位方式" font:20 Frame:CGRectMake(0, 0, self.frame.size.width, 50)];
    label.textAlignment = NSTextAlignmentCenter;
   [self addSubview:label];
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(self.frame.size.width - 40, 10, 30, 30);
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"ico_closs@2x"] forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cancelBtn];
    //添加wife定位
    [self addUicontrolFrame:CGRectMake(0, 50, self.frame.size.width, 50) Name:@"WIFI定位" font:20 headImageName:@"ico_wifi2" footImageName:nil tag:0];
    //添加wife定位具体方式
    [self addUicontrolFrame:CGRectMake(20, 100, self.frame.size.width, 50) Name:@"探针+Palmap定位引擎" font:14 headImageName:nil footImageName:@"btn_grey" tag:1];
    [self addUicontrolFrame:CGRectMake(20, 150, self.frame.size.width, 50) Name:@"寰创+Palmap定位引擎" font:14 headImageName:nil footImageName:@"btn_grey" tag:2];
    [self addUicontrolFrame:CGRectMake(20, 200, self.frame.size.width, 50) Name:@"寰创+云景定位引擎" font:14 headImageName:nil footImageName:@"btn_grey" tag:3];
    [self addUicontrolFrame:CGRectMake(20, 250, self.frame.size.width, 50) Name:@"贝尔特+Palmap定位引擎" font:14 headImageName:nil footImageName:@"btn_grey" tag:4];
    //添加蓝牙定位
    [self addUicontrolFrame:CGRectMake(0, 300, self.frame.size.width, 50) Name:@"蓝牙定位" font:20 headImageName:@"ico_bluetooth2@2x" footImageName:@"btn_grey" tag:5];
}

-(UILabel *)addTitleView:(NSString *)title font:(CGFloat)size Frame:(CGRect)frame{
    UILabel *label = [[UILabel alloc]init];
    label.frame = frame;
    label.text = title;
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:size];
    return label;
    

}

-(UILabel *)addLabeline:(CGRect)frame{
    UILabel *label = [[UILabel alloc]init];
    label.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 1);
    label.backgroundColor = [UIColor lightGrayColor];
    return label;
}

-(void)addUicontrolFrame:(CGRect)frame Name:(NSString *)name font:(CGFloat)fontSize headImageName:(NSString *)HimageName footImageName:(NSString *)FimageName tag:(NSInteger)tag{
    CGSize headSize = CGSizeMake(25, 40);
    CGSize footSize = CGSizeMake(20, 20);
    //蓝牙定位
    UIControl *tempControl;
    if (HimageName && FimageName) {
        tempControl = [[UIControl alloc]initWithFrame:frame];
        
        UIImageView *headView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, headSize.width , headSize.height)];
        headView.image = [UIImage imageNamed:HimageName];
        [tempControl addSubview:headView];
        
        UIImageView *footView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width - 10 - footSize.width, 10, footSize.width, footSize.height)];
        footView.image = [UIImage imageNamed:FimageName];
        [tempControl addSubview:footView];
        footView.tag = 100;
        [tempControl addSubview:[self addTitleView:@"蓝牙定位" font:20 Frame:CGRectMake(CGRectGetMaxX(headView.frame) + 5, 15, 200, 30)]];
        tempControl.tag = 5;
        [tempControl addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
        [tempControl addSubview:[self addLabeline:CGRectMake(20, 55, 60, 1)]];
    //Wifi定位
    }else if (HimageName && !FimageName){
        
        tempControl = [[UIControl alloc]initWithFrame:frame];
        
        UIImageView *headView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, headSize.width , headSize.height)];
        headView.image = [UIImage imageNamed:HimageName];
        [tempControl addSubview:headView];
        
        [tempControl addSubview:[self addTitleView:@"WIFI定位" font:20 Frame:CGRectMake(CGRectGetMaxX(headView.frame) + 5, 15, 200, 30)]];
        [tempControl addSubview:[self addLabeline:CGRectMake(20, 55, 60, 1)]];
    //Wifi定位具体方式
    }else if (!HimageName && FimageName){
        tempControl = [[UIControl alloc]initWithFrame:frame];
        
        
        UIImageView *footView = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width - 30 - footSize.width, 10, footSize.width, footSize.height)];
        footView.image = [UIImage imageNamed:FimageName];
        footView.tag = 100;
        [tempControl addSubview:footView];
        
        [tempControl addSubview:[self addTitleView:name font:fontSize Frame:CGRectMake(headSize.width + 20, 10, 200, 30)]];
        [tempControl addSubview:[self addLabeline:CGRectMake(headSize.width + 20, 50, 200, 1)]];
        tempControl.tag = tag;
        [tempControl addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    [self addSubview:tempControl];
}

-(void)controlAction:(UIControl *)control{

   // _locStyle = (int)control.tag;
    //[self setCurrentLocationStyle:_locStyle];
    switch (control.tag) {
        case 1:
        {
            NSLog(@"探针+Palmap定位引擎");
        }
            break;
        case 2:
        {
            NSLog(@"寰创+Palmap定位引擎");
        }
            break;
        case 3:
        {
            NSLog(@"寰创+云景定位引擎");
        }
            break;
        case 4:
        {
            NSLog(@"贝尔特+Palmap定位引擎");
        }
            break;
        case 5:
        {
            NSLog(@"蓝牙定位");
        }
            break;
            
        default:
            break;
    }
    [self removeFromSuperview];
//    if (self.myblock) {
//        self.myblock(_locStyle);
//    }
//    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(timerAction) userInfo:nil repeats:NO];
}

-(void)timerAction{
    [self removeFromSuperview];
//    if (self.myblock) {
//        self.myblock(_locStyle);
//    }
}
-(void)cancelAction{
//    [self removeFromSuperview];
//    if (self.myblock) {
//        //点击删除按钮
//        self.myblock(-1);
//    }
}

//-(void)setCurrentLocationStyle:(LocationStyle)style{
//    _locStyle = style;
//    UIControl *tempCon = [self viewWithTag: _locStyle];
//    UIImageView *imageView = [tempCon viewWithTag:100];
//    imageView.image = [UIImage imageNamed:@"btn_blue_pre@2x"];
//    if (!self.oldImageView) {
//        self.oldImageView = imageView;
//    }else if(self.oldImageView != imageView){
//        self.oldImageView.image = [UIImage imageNamed:@"btn_grey"];
//        self.oldImageView = imageView;
//    
//    };
//}



@end
